<template>
  <div class="table-pagination">
    <el-pagination
      :background="background"
      :current-page="page"
      :page-size="pageSize"
      :page-sizes="pageSizes"
      :total="total"
      :layout="layout"
      :small="small"
      v-bind="$attrs"
      @size-change="sizeChangeHandle"
      @current-change="pageChangeHandle" />
  </div>
</template>

<script>
export default {
  name: 'table-pagination',
  props: {
    total: {
      required: true,
      type: Number,
      default: 0
    },
    page: {
      type: Number,
      default: 1
    },
    pageSize: {
      type: Number,
      default: 15
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 15, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: 'jumper, prev, pager, next, total, sizes'
    },
    background: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    },
    small: {
      type: Boolean,
      default: false
    }
  },
  computed: {},
  methods: {
    sizeChangeHandle(val) {
      console.debug('table pagination sizeChangeHandle >> ' + val)
      this.$emit('pageHandle', { page: this.page, pageSize: val })
    },
    pageChangeHandle(val) {
      console.debug('table pagination pageChangeHandle >> ' + val)
      this.$emit('pageHandle', { page: val, pageSize: this.pageSize })
    }
  }
}
</script>

<style lang="scss" scoped>
.table-pagination {
  background: #fff;
  padding: 0 10px;
  > .el-pagination {
    margin-top: 10px;
  }
}
</style>
